
#include <iostream>
#include "TBPlatform.h"
#include "Nike.h"
#include "Anta.h"
#include "ASUS.h"
#include "Huawei.h"

int main(int argc, char* argv[])
{
  Platform* tbp = new TBPlatform();
  Merchant* nike = new Nike(1);
  Merchant* anta = new Anta(2);
  Merchant* asus = new ASUS(3);
  Merchant* hw = new Huawei(4);
  // 商家注册
  tbp->Registry(nike);
  tbp->Registry(anta);
  tbp->Registry(asus);
  tbp->Registry(hw);
  // 各个同事组件间相互通信的函数
  hw->Send(3, "你好，我是HUAWEI");
  nike->Send(2, "你好！同行");
  asus->Send(1, "今天生意怎么样");
  // 客户端借助中介者间接和其他组件交互
  for (Commodity& c : *(tbp->Search("笔记本电脑")))
    std::cout << c.get_brand() << "-->" << c.get_price() << std::endl;

  delete tbp; // 析构中介对象即可，其中的维护的组件也会一并销毁
  return 0;
}